package com.ruoyi.classinfo.service.impl;

import com.ruoyi.classinfo.domain.AtDTO;
import com.ruoyi.classinfo.domain.AtVO;
import com.ruoyi.classinfo.mapper.AtqkMapper;
import com.ruoyi.classinfo.service.IAtqkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AttendanceServiceImpl implements IAtqkService {

    @Autowired
    private AtqkMapper attendanceRecordMapper;

    @Override
    public AtVO getAttendanceStats(String teacherId) {
        // 查询数据库获取统计数据
        List<AtDTO> statsList = attendanceRecordMapper.countAllByCheckType(teacherId);

        // 转换为前端需要的格式
        Map<String, Integer> statsMap = new HashMap<>();
        statsMap.put("正常", 0);
        statsMap.put("晚归", 0);
        statsMap.put("未归", 0);

        for (AtDTO dto : statsList) {
            statsMap.put(dto.getCheckType(), dto.getCount());
        }
        System.out.println(statsMap);

        // 构建返回对象
        AtVO vo = new AtVO();
        vo.setStats(statsMap);

        return vo;
    }
}
